package com.lannuokeji.utils.tags.map;

import java.util.Map;

import org.beetl.core.GeneralVarTagBinding;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

/**
 * 顶部导航标签
 * @author zzp
 * 调用方式：<dataList fields="字段名用半角逗号隔开" table="表名" where="where后面跟的查询条件" >
 * </@jm.dataList>
 */
@Service
@Scope("prototype")
public class DataListTag extends GeneralVarTagBinding {

	public static String tagName = "dataList";
	
	@Override
	public void render() {
		Map<String, String> attrs = (Map<String, String>) this.args[1];
		
		String querySql = "select ";
		// 接收所要查询的参数，如果为空那么赋值为*
		String getFields = attrs.get("fields");
		String fields = (getFields == null) ? "*" : getFields;
		querySql += fields;

		querySql += " from ";

		// 接收传过来的表名，没有表名不行
		String tableName = attrs.get("table");
		if (tableName == null) {
			return;
		}
		querySql += tableName;
		
		// 接收where需要拼接的条件
		String where = attrs.get("where");
		if (where != null) {
			querySql += " where ";
			querySql += where;
		}
		// 排序
		String orderBy = attrs.get("orderBy");
		if (orderBy != null) {
			querySql += " order by ";
			querySql += orderBy;
		}
		// 限制记录条数
		String limit = attrs.get("limit");
		if (limit != null) {
			querySql += " limit ";
			querySql += limit;
		}
//		List<User> dataList = userService.selectList(Condition.EMPTY);
//		List<Record> dataList = Db.find(querySql);
		this.binds("abc");
		this.doBodyRender();
	}

}
